package com.bkgy.modular.tbdsjtcmplanwt.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.tbdsjtcmplanwt.dao.TbDsjTcmPlanWtMapper;
import com.bkgy.modular.tbdsjtcmplanwt.entity.TbDsjTcmPlanWt;
import com.bkgy.modular.tbdsjtcmplanwt.service.TbDsjTcmPlanWtService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


@Service
public class TbDsjTcmPlanWtServiceImpl extends ServiceImpl<TbDsjTcmPlanWtMapper, TbDsjTcmPlanWt>
    implements TbDsjTcmPlanWtService {

    @Override
    public ResultData findDataByPage(JSONObject json) {
        try {
            Integer pageIndex = json.getInteger("pageIndex");
            Integer pageSize = json.getInteger("pageSize");
            //查询条件暂无，后续需要再根据需求添加
            JSONObject condition = json.getJSONObject("condition");
            if(null == pageIndex || null == pageSize){
                return ResultData.ResultDataFaultSelf("分页参数没有传", null);
            }
            QueryWrapper<TbDsjTcmPlanWt> wrapper = new QueryWrapper<>();
            if (!condition.isEmpty()) {
                //产线
                if (StringUtils.hasText(condition.getString("productline"))) {
                    String productline = condition.getString("productline");
                    wrapper.lambda().eq(TbDsjTcmPlanWt::getProductline,productline);
                }
                //计划号
                if (StringUtils.hasText(condition.getString("plan_no"))) {
                    String plan_no = condition.getString("plan_no");
                    wrapper.lambda().like(TbDsjTcmPlanWt::getPlan_no,plan_no);
                }
            }
            wrapper.lambda().orderByDesc(TbDsjTcmPlanWt::getCreatetime);
            Page<TbDsjTcmPlanWt> page = new Page<>(pageIndex,pageSize);
            Page<TbDsjTcmPlanWt> tbDsjTcmPlanWtPage = this.page(page, wrapper);
            return ResultData.ResultDataSuccess(tbDsjTcmPlanWtPage.getRecords(), (int) tbDsjTcmPlanWtPage.getTotal());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }
}




